<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>微博发布</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<script src="js/jquery-1.4.2.min.js"></script>
<script src="js/common.js"></script>
<script src="js/consumer.js?v=2.4"></script>
<script src="js/oauth.js?v=1020"></script>
<script src="js/sha1.js"></script>

<style>
body {
	color:#333;
	line-height:180%;
	margin:0px;
	padding:0px;
	overflow:hidden;
	font-size:12px;
}
*{font-family:微软雅黑,Trebuchet MS, Arial, Helvetica, Sans-Serif;font-size:12px;line-height:150%}
*:focus {outline: 0;} 
#main{width:590px;height:600px;position:relative;padding:0px;margin:0px;padding-left:10px;}
h3{font-size:15px;margin:0px;padding:15px 0px 0px 0px;}
{font-size:15px;font-weight:bold;padding:5px;}
.title{float:left;height:20px;padding:15px 0px 5px 0px}
#weibotext,#longtext{float:left;width:560px;}
#content{width:550px;resize:none;height:75px;background:#FFFCD9}
#wordcount{position:absolute;right:50px;top:80px}
#wordcount span{font-size:30px;font-weight:bold;font-family: Constantia, Georgia;}
#longcontent{width:550px;height:320px;font-size:12px;resize:none;background:#FFFCD9}

#btn_format{position:absolute;top:490px;right:140px;width:60px;height:28px;}
#btn_post{position:absolute;top:530px;right:55px;width:60px;height:28px;}
#followse{position:absolute;top:530px;left:15px;width:60px;height:28px;}


#msg_tip{background:#fff;width:240px;height:55px;position:absolute;top:250px;left:160px;z-index:999;border:solid #fff 1px;border-radius:5px;box-shadow:1px 2px 2px #bbb;display:none;text-align:center;padding-top:30px;opacity:0.8;color:#ff0000;font-size:15px;}
#selectpic{position:absolute;top:225px;left:60px;background:url(images/weibo_selectpic.gif?v=1) no-repeat 0px 2px;z-index:888;width:100px;height:30px;padding-left:20px;text-align:left;cursor:pointer}
#picshow{position:absolute;left:60px;top:250px}
#picshow img{border:solid #ccc 1px;position:absolute;left:0px;top:0px;z-index:1000;cursor:pointer}
</style>

<script>
var accessToken = localStorage.getItem("oauth2_accessToken");
var OAuth = OAuth || {};

BIG_FONT_WIDTH = 88;
 
function format(v,w,c){
	c = 0;
	w = w || BIG_FONT_WIDTH;
	return v.replace(/[\S\s]/g,function(a){
		if(/[\r\n]/.test(a)) {
			c = -2;
			return "\r\n";
		}
		c += /[\x00-\xFF]/.test(a) ? 1 : 2;
		if(c>=w){
			c = 0;
			return "\r\n"+a;
		}
		return a;
	});
}
$(function(){
	$("#btn_post").click(function(){
		if($("#longcontent").val().length<1){
			showError("长微博的内容不能为空！");
		} else {
			$("#longcontent").val(format($("#longcontent").val()));
			$.ajax({
				type:"POST",
				url:"http://ie.sogou.com/skins/?route=app/long",
				data:"&text=" + $("#content").val() + "&longtext="+$("#longcontent").val() + "&oauth_token=" + accessToken,
				dataType:"html",
				success:function(html){
					if(html == "1"){
						showSucc();
					} else {
						showError("长微博发布失败，请重试！");
					}
				}
			});
		}
	});
 });
 

function showSucc(){
	$("#msg_tip").remove();
	$("body").append("<div id='msg_tip'><img src='images/weibo_post_succ.gif?v=3' /></div>");
	$("#msg_tip").fadeIn();
	var t = setTimeout(function(){$("#msg_tip").fadeOut();$("#content").val("");$("#longcontent").val("");}, 2000);
}

function showError(msg){
	$("#msg_tip").remove();
	$("body").append("<div id='msg_tip'>" + msg + "</div>");
	$("#msg_tip").fadeIn();
	var t = setTimeout(function(){$("#msg_tip").fadeOut();}, 2000);
}

$(document).ready(function(){
	$("#content").focus();
});

</script>
</head>
<body>
<div id="main">
	<h3>发布长微博</h3>
	<div class="title">输入微博正文</div>
	<div id="weibotext"><textarea id="content" maxlength=140></textarea></div>
	<div class="title">请将需要生成长微博的文字内容，粘贴到下面的文本框中</div>
	<!--<div id="selectpic">选择本地图片</div>-->
	<div id="longtext"><textarea id="longcontent"></textarea></div>
	<!--<div><button id="btn_format">格式化</button>--><button id="btn_post">发 布</button></div>
	<div style="position:absolute;left:-400px;"><input type="file" id="pic" name="pic" /></div>
</div>
</body>
</html>
